package com.ruoyi.reservationserver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.mapper.StadiumStatisticMapper;
import com.ruoyi.system.domain.StadiumStatistic;
import com.ruoyi.reservationserver.service.StadiumStatisticService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 球馆数据统计表
(StadiumStatistic)表服务实现类
 *
 * @author makejava
 * @since 2023-07-04 16:21:49
 */
@Service("stadiumStatisticService")
public class StadiumStatisticServiceImpl extends ServiceImpl<StadiumStatisticMapper, StadiumStatistic> implements StadiumStatisticService {
    @Resource
    private StadiumStatisticMapper stadiumStatisticMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param stadiumStatisticId 主键
     * @return 实例对象
     */
    @Override
    public StadiumStatistic queryById(Integer stadiumStatisticId) {
        return this.stadiumStatisticMapper.queryById(stadiumStatisticId);
    }

    /**
     * 分页查询
     *
     * @param stadiumStatistic 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<StadiumStatistic> queryByPage(StadiumStatistic stadiumStatistic, PageRequest pageRequest) {
        long total = this.stadiumStatisticMapper.count(stadiumStatistic);
        return new PageImpl<>(this.stadiumStatisticMapper.queryAllByLimit(stadiumStatistic, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param stadiumStatistic 实例对象
     * @return 实例对象
     */
    @Override
    public StadiumStatistic insert(StadiumStatistic stadiumStatistic) {
        this.stadiumStatisticMapper.insert(stadiumStatistic);
        return stadiumStatistic;
    }

    /**
     * 修改数据
     *
     * @param stadiumStatistic 实例对象
     * @return 实例对象
     */
    @Override
    public StadiumStatistic update(StadiumStatistic stadiumStatistic) {
        this.stadiumStatisticMapper.update(stadiumStatistic);
        return this.queryById(stadiumStatistic.getStadiumStatisticId());
    }

    /**
     * 通过主键删除数据
     *
     * @param stadiumStatisticId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer stadiumStatisticId) {
        return this.stadiumStatisticMapper.deleteById(stadiumStatisticId) > 0;
    }
}
